package com.lm.upms.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lm.common.core.util.R;
import com.lm.common.log.annotation.SysLog;
import com.lm.common.log.enums.BusinessType;
import com.lm.upms.api.entity.SysOauthClientDetails;
import com.lm.upms.service.ISysOauthClientDetailsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 客户端
 *
 * @author lm
 * @date 2019-09-03
 */
@Api(tags = "客户端")
@Slf4j
@RestController
@RequestMapping("sysOauthClientDetails")
public class SysOauthClientDetailsController {

    @Autowired
    private ISysOauthClientDetailsService sysOauthClientDetailsService;

    /**
     * 分页列表查询
     *
     * @param page
     * @param sysOauthClientDetails 客户端
     * @return
     */
    @ApiOperation(value = "分页列表查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "page", required = true, dataType = "Page"),
            @ApiImplicitParam(name = "sysOauthClientDetails", value = "sysOauthClientDetails", required = true, dataType = "SysOauthClientDetails")
    })
    @GetMapping("/page")
    public R<IPage<SysOauthClientDetails>> getSysOauthClientDetailsPage(Page<SysOauthClientDetails> page, SysOauthClientDetails sysOauthClientDetails) {
        return R.success(sysOauthClientDetailsService.getSysOauthClientDetailsPage(page, sysOauthClientDetails));
    }

    /**
     * 根据id查询
     *
     * @param clientId
     * @return
     */
    @GetMapping("/{clientId}")
    public R<SysOauthClientDetails> getById(@PathVariable("clientId") String clientId) {
        return R.success(sysOauthClientDetailsService.getById(clientId));
    }

    /**
     * 新增
     *
     * @param sysOauthClientDetails
     * @return
     */
    @SysLog(title = "客户端管理", businessType = BusinessType.INSERT)
    @PostMapping("save")
    public R save(@RequestBody SysOauthClientDetails sysOauthClientDetails){
        return R.success(sysOauthClientDetailsService.save(sysOauthClientDetails));
    }

    /**
     * 修改
     *
     * @param sysOauthClientDetails
     * @return
     */
    @SysLog(title = "客户端管理", businessType = BusinessType.UPDATE)
    @PostMapping("update")
    public R update(@RequestBody SysOauthClientDetails sysOauthClientDetails) {
        return R.success(sysOauthClientDetailsService.updateById(sysOauthClientDetails));
    }

    /**
     * 删除
     *
     * @param clientId
     * @return
     */
    @SysLog(title = "客户端管理", businessType = BusinessType.DELETE)
    @PostMapping("remove")
    public R remove(String clientId) {
        return R.success(sysOauthClientDetailsService.removeById(clientId));
    }

}
